#include <vector>//1011 O(n log S) O(1)
using namespace std;
static inline bool feasible(const int* a, int n, int days, int C){
int need = 1, cur = 0;
for(int i=0;i<n;++i){
int x = a[i];
if(cur + x > C){
if(++need > days) return false;
cur = x;// start next day with this package
}else{
cur += x;
}
}
return true;
}
class Solution{
public:
int shipWithinDays(vector<int>& w, int days){
const int n = (int)w.size();
const int* a = w.data();
int L = 0, S = 0;// single pass: lower bound=max weight, upper bound=sum (both fit 32-bit)
for(int i=0;i<n;++i){ int x=a[i]; if(x>L) L=x; S += x; }
int R = S;
if(days == n) return L;
if(days == 1) return R;
while(L < R){
int m = (L + R) / 2;
if(feasible(a, n, days, m)) R = m; // feasible → try smaller
else L = m + 1;// infeasible → increase
}
return L;// minimal feasible capacity
}
};
Gemini CLI 表示:
✦ 當然,要讓咳嗽快點好,可以從幾個方面著手,結合居家照護、飲食調整和生活習慣改變。
請注意:我是一個AI助理,以下的建議不能取代專業醫療診斷。如果咳嗽持續、惡化,或伴隨高燒、呼吸困難等嚴重症狀
,請務必諮詢醫生。
這裡為您整理出一些最有效且公認的方法,可以分為幾個大類:
一、 立即舒緩與居家照護 (Immediate Relief & Home Care)
看來參加鐵人賽並沒有幫助
挖剛看留言期間邊吃完一個快樂的健達巧克力 哈